import java.util.Scanner;

public class The_greatest_common_divisor {
    public static void main(String[] args) {
        //辗转相除法
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        int b = s.nextInt();
        int c = a % b;
        while(c != 0){
            a = b;
            b = c;
            c = a % b;
        }
        System.out.println(b);
    }
    public static void main1(String[] args) {
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        int b = s.nextInt();
        int n = 0;
        for (int i = 1; i < (a > b ? b: a); i++) {
            if (a % i == 0 && b % i ==0) {
                n = i;
            }
        }
        System.out.println(n);
    }
}
